<?php
	require_once("utils.php");
	require_once("obj/role.php"); 
	require_once("obj/session.php");
	require_once("obj/user.php");
	
	//globals like ($role, $session, etc..) can be used on any sub page
	$page = Utils::getPageFromURL();
	$session = Session::getFromURL();
	$sid = "";
	$role = "";
	$user = new User();
	
	if($session != null){
		if($session->isAlive()) {
			$sid = $session->SID;
			$roleobj = Role::getBySession($sid);
			$role = $roleobj == null ? "" : $roleobj->Name;
			$user = User::getByUserId($session->UserId);
		}
		else {
			$session->logout($sid);
		}
	}
?>

<html>
	<head>
		<title>Task Tracker</title>
		<link rel="stylesheet" href="master.css" type="text/css" media="screen" />
		<script type="text/javascript" src="js/jquery-1.6.4.min.js"></script>
		<script type="text/javascript" src="js/jquery.corners.min.js"></script>
		<script type="text/javascript" src="js/utils.js"></script>
	</head>
	<body>
		<div id="container">
		<div id="logo">Task Tracker</div>
		<div><?php echo "Hello, ".$user->Email." ($role)"; ?></div><br/>
		<?php
			if($role == "Admin") {
		?>	
			<a class="<?php echo $page == "users" || $page == "userdetails" ? 'selectedtab' : 'tab'; ?>" href="index.php?<?php echo "sid=$sid"?>&page=users">Users</a>
		<?php } ?>
		
		<?php
			if($role == "Admin" || $role == "Manager") {
		?>
			<a class="<?php echo $page == "projects" || $page == "projectdetails" ? 'selectedtab' : 'tab'; ?>" href="index.php?<?php echo "sid=$sid"?>&page=projects">Projects</a>
		<?php } ?>
			<a class="<?php echo $page == "tasks" || $page == "taskdetails" || $page == "tasktime" || $page == "tasktimedetails" ? 'selectedtab' : 'tab'; ?>" href="index.php?<?php echo "sid=$sid"?>&page=tasks">Tasks</a>
		<?php
			if($role == "Admin") {
		?>
			<a class="<?php echo $page == "taskpriorities" || $page == "taskprioritydetails" ? 'selectedtab' : 'tab'; ?>" href="index.php?<?php echo "sid=$sid"?>&page=taskpriorities">Priorities</a>
		<?php } ?>
			<a class="<?php echo $page == "reports" ? 'selectedtab' : 'tab'; ?>" href="index.php?<?php echo "sid=$sid"?>&page=reports">Reports</a>
			<a class="tab" href="index.php?<?php echo "sid=$sid"?>&page=logout" onclick="return confirm('Do you really want to logout?');">Logout</a>			
		
			<div id="content">
			<?php								
				if(($session == null || strlen($role) == 0) && $page != "forgot" && $page != "resetpwd") {
					$page = "login";
				}
				
				$page = trim(strtolower($page));
				
				if(($page == "users" || $page == "userdetails") && $role != "Admin") {
					$page = "tasks";
				}
				
				if(($page == "projects" || $page == "projectdetails") && $role == "User") {
					$page = "tasks";
				}
				
				if(($page == "taskpriorities" || $page == "taskprioritydetails") && $role != "Admin") {
					$page = "tasks";
				}
				
				if(($page == "taskdetails") && $role == "User") {
					$page = "tasks";
				}
				
				include($page.".php");				
			?>
			</div>
		</div>		
	</body>
</html>